package com.sitech.ibnms.core;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.sitech.BaseConst;
import com.sitech.context.SpringContext;
import com.sitech.portal.system.dao.ISysUserRoleDao;
import com.sitech.portal.system.domain.TblSYS_LOGINMSG;
import com.sitech.portal.system.domain.TblSYS_ROLE;

/**
 * 
 * <p>
 * Title: BaseIbnmsService.java
 * </p>
 * <p>
 * Description:**ServiceImpl都要继承的类
 * </p>
 * <p>
 * Copyright: Copyright (c) SITECH 2011
 * </p>
 * 
 * @author LJ
 * @date Sep 30, 2011 11:14:06 AM
 * @version V6.0
 */
public class BaseIbnmsService {
	protected Log log = LogFactory.getLog(getClass());

	//得到当前用户
	public TblSYS_LOGINMSG  getCurrentUser()
	{
		
		return (TblSYS_LOGINMSG)ServletActionContext.getRequest().getSession().getAttribute(BaseConst.SESSION_USER_KEY);
	}
	//得到当前用户Session
	public HttpSession  getCurrentUserSession()
	{
		
		return (HttpSession)ServletActionContext.getRequest().getSession();
	}
	//得到用户关联的角色ID列表
	public List<String>  getCurrentUserRoleIdList() throws Exception
	{
		List<String> roleIdList=null;
		
		List<TblSYS_ROLE>  roleList=(List<TblSYS_ROLE>)ServletActionContext.getRequest().getSession().getAttribute(BaseConst.SESSION_USER_ROL_KEY);
		if(roleList==null || roleList.size()==0){
			ISysUserRoleDao sysUserRoleDao = (ISysUserRoleDao) SpringContext.getBean("sysUserRoleDao");
			roleList=(List<TblSYS_ROLE>)sysUserRoleDao.findRoleListByUserId(this.getCurrentUser().getUSER_ID());
			ServletActionContext.getRequest().getSession().setAttribute(BaseConst.SESSION_USER_ROL_KEY, roleList);
		}
		
		if(roleList!=null && roleList.size()>0)
		{
			roleIdList=new ArrayList();
			for(TblSYS_ROLE role:roleList)
			{
				roleIdList.add(role.getROLE_ID());
			}
		}
		return roleIdList;
	}
}
